package com.atguigu.day11.exer.area;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/12 10:39
 * @注释
 */
public class Test {


    public static void main(String[] args) {
        Graphic[] graphics = getGraphics();

        showInfo("排序前", graphics);
        System.out.println("----------------------------------------------------");
        sort(graphics);

        showInfo("排序后", graphics);
    }


    private static Graphic[] getGraphics() {
        Circle c1 = new Circle(9);
        Circle c2 = new Circle(100);
        Rectangle r1 = new Rectangle(100, 20);
        Rectangle r2 = new Rectangle(9, 12);

        Graphic[] graphics = new Graphic[]{c1, c2, r1, r2};
        return graphics;
    }

    private static void showInfo(String massage, Graphic[] graphics) {
        for (Graphic graphic : graphics) {
            String info = graphic.getInfo();
            System.out.println(info);
        }
    }

    private static void sort(Graphic[] graphics) {
        for (int i = 0; i < graphics.length; i++) {
            for (int j = 0; j < graphics.length - 1; j++) {
                if (graphics[j].area() > graphics[j + 1].area()) {
                    Graphic[] temp = new Graphic[1];
                    temp[0] = graphics[j];
                    graphics[j] = graphics[j + 1];
                    graphics[j + 1] = temp[0];
                }
            }
        }
    }
}
